package com.liangwj.springbootquickstart.MultiDataSource;

/**
 * TODO:创建DynamicDataSourceHolder用于持有当前线程中使用的数据源标识
 * @author Liangwenjun
 * @date 2018-12-12
 * @version 1.0
 */
public class DynamicDataSourceHolder {

    /**
     * 注意：数据源标识保存在线程变量中，避免多线程操作数据源时互相干扰
     */
    private static final ThreadLocal<String> THREAD_DATASOURCE = new ThreadLocal<>();

    public static String getThreadDataSource() {
        return THREAD_DATASOURCE.get();
    }

    public static void setThreadDatasource(String dataSource) {
        THREAD_DATASOURCE.set(dataSource);
    }

    public static void removeThreadDataSource() {
        THREAD_DATASOURCE.remove();
    }
}
